// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ASSOCIATED_PERSON_PEX_P07 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("56 NK1",56)]
  	    [HL7Field(HL7Version.v23, 56, HL7Repeat.False, HL7Required.True,"NK1")]
	    public NK1 NK1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("57 ASSOCIATED_RX_ORDER",57)]
  	    [HL7Field(HL7Version.v23, 57, HL7Repeat.False, HL7Required.False,"ASSOCIATED_RX_ORDER_PEX_P07")]
	    public ASSOCIATED_RX_ORDER_PEX_P07 ASSOCIATED_RX_ORDER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("65 ASSOCIATED_RX_ADMIN",65)]
  	    [HL7Field(HL7Version.v23, 65, HL7Repeat.False, HL7Required.False,"ASSOCIATED_RX_ADMIN_PEX_P07")]
	    public ASSOCIATED_RX_ADMIN_PEX_P07 ASSOCIATED_RX_ADMIN {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			NK1 = PopSegmentParseAndCheckRequired<NK1>(availableData, options, "NK1");
			ASSOCIATED_RX_ORDER = ProcessGroup<ASSOCIATED_RX_ORDER_PEX_P07>(availableData, options, "ASSOCIATED_RX_ORDER");
			ASSOCIATED_RX_ADMIN = ProcessGroup<ASSOCIATED_RX_ADMIN_PEX_P07>(availableData, options, "ASSOCIATED_RX_ADMIN");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isNK1 = availableData.StartsWith("NK1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NK1", options.Version) || isNK1) {
				return isNK1;
			}
			ASSOCIATED_RX_ORDER_PEX_P07 testASSOCIATED_RX_ORDER_PEX_P07 = new ASSOCIATED_RX_ORDER_PEX_P07();
			bool grpCCASSOCIATED_RX_ORDER_PEX_P07 = (testASSOCIATED_RX_ORDER_PEX_P07.CanConsume(availableData, options));
			if (IsRequired("ASSOCIATED_RX_ORDER", options.Version) || grpCCASSOCIATED_RX_ORDER_PEX_P07) {
				return grpCCASSOCIATED_RX_ORDER_PEX_P07;
			}
			ASSOCIATED_RX_ADMIN_PEX_P07 testASSOCIATED_RX_ADMIN_PEX_P07 = new ASSOCIATED_RX_ADMIN_PEX_P07();
			bool grpCCASSOCIATED_RX_ADMIN_PEX_P07 = (testASSOCIATED_RX_ADMIN_PEX_P07.CanConsume(availableData, options));
			if (IsRequired("ASSOCIATED_RX_ADMIN", options.Version) || grpCCASSOCIATED_RX_ADMIN_PEX_P07) {
				return grpCCASSOCIATED_RX_ADMIN_PEX_P07;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ASSOCIATED_PERSON";
			}
        }

        static ASSOCIATED_PERSON_PEX_P07() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ASSOCIATED_PERSON_PEX_P07));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (NK1 != null) {
			string segmentValue = NK1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ASSOCIATED_RX_ORDER != null) {
			string segmentValue = ASSOCIATED_RX_ORDER.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ASSOCIATED_RX_ADMIN != null) {
			string segmentValue = ASSOCIATED_RX_ADMIN.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

